/**
 * Copyright (C) <2023> <Boundivore> <boundivore@foxmail.com>
 * <p>
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the Apache License, Version 2.0
 * as published by the Apache Software Foundation.
 * <p>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * Apache License, Version 2.0 for more details.
 * <p>
 * You should have received a copy of the Apache License, Version 2.0
 * along with this program; if not, you can obtain a copy at
 * http://www.apache.org/licenses/LICENSE-2.0.
 */
import React, { FC, useState, useCallback } from 'react';
import RollbackModal from './rollbackModal';
import { NodeDropdownButton } from './nodeDropdownButton';
import { MessageInstance } from 'antd/es/message/interface';
interface RollbackProps {
	fileName: string;
	messageApi: MessageInstance;
	callback: () => void;
}
const Rollback: FC<RollbackProps> = ({ fileName, messageApi, callback }) => {
	const [isModalOpen, setIsModalOpen] = useState<boolean>(false);

	const handleModalCancel = useCallback(() => {
		setIsModalOpen(false);
	}, []);
	return (
		<>
			<NodeDropdownButton
				buttonText="查看历史并回滚"
				callBack={() => {
					setIsModalOpen(true);
				}}
			/>

			{isModalOpen ? (
				<RollbackModal
					isModalOpen={isModalOpen}
					handleCancel={handleModalCancel}
					fileName={fileName}
					messageApi={messageApi}
					callback={callback}
				/>
			) : null}
		</>
	);
};
export default Rollback;
